package com.meituan.service.impl;

import com.meituan.mapper.GoodsClassifyMapper;
import com.meituan.mapper.GoodsMapper;
import com.meituan.model.GoodsClassifyEntity;
import com.meituan.service.GoodsClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

@Service
@Transactional
public class GoodsClassifyServiceImpl implements GoodsClassifyService {
    @Autowired
    GoodsClassifyMapper goodsClassifyMapper;
    @Autowired
    GoodsMapper goodsMapper;
    @Override
    public List<GoodsClassifyEntity> findByShopIdWithGoods(String shopId) {
        return goodsClassifyMapper.findByShopIdWithGoods(shopId);
    }

    @Override
    public List<GoodsClassifyEntity> findByShopId(String shopId) {
        return goodsClassifyMapper.findByShopId(shopId);
    }

    @Override
    public Integer add(GoodsClassifyEntity goodsClassifyEntity) {
        return goodsClassifyMapper.save(goodsClassifyEntity);
    }

    @Override
    public GoodsClassifyEntity findById(String classifyId) {
        return goodsClassifyMapper.findById(classifyId);
    }

    @Override
    public Integer delete(String classifyId) {
        if(goodsClassifyMapper.delete(classifyId)==1){
            goodsMapper.delGoodsByClassifyId(classifyId);
            return 1;
        }
        return 0;
    }

    @Override
    public Integer updateClassifyName(String classifyName, String classifyId) {
        return goodsClassifyMapper.updateClassifyName(classifyName,classifyId);
    }
}
